﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WinNemoLib;
using System.Data.SqlClient;
using System.Data;
using System.Text;

namespace Bias_Stock.Models
{
    public class CountCartModel
    {
        public class data_ds
        {
            public string _area { get; set; }
            public string _cart { get; set; }
            public string _tag { get; set; }
            public string _msg { get; set; }
        }
        public class PlyRoll_DS
        {
            public string _biasno { get; set; }
            public string _plandt { get; set; }
            public string _itemno { get; set; }
            public string _sitemno { get; set; }
            public string _prddate { get; set; }

            public string _side { get; set; }
            public string _rollno { get; set; }
            public string _cartno { get; set; }
            public string _plylot { get; set; }
            public string _plyexp { get; set; }
            public string _plylen { get; set; }
            public string _Plyan1 { get; set; }
            public string _Plyan2 { get; set; }
            public string _Plyan3 { get; set; }
            public string _Plywd1 { get; set; }
            public string _Plywd2 { get; set; }
            public string _Plywd3 { get; set; }
            public string _Plymin { get; set; }
            public string _Plyjn1 { get; set; }
            public string _Plyjn2 { get; set; }
            public string _Plyjn3 { get; set; }
            public string _empname { get; set; }
            public string _shift { get; set; }
            public string _update { get; set; }
            public string _Ply { get; set; }
            public string _Ply1 { get; set; }
            public string _Ply2 { get; set; }

            public string _topcode { get; set; }
            public string _sizes { get; set; }
            public string _forming { get; set; }
            public string _toproll { get; set; }
            public string _topexp { get; set; }
            public string _toplen { get; set; }
            public string _topLot { get; set; }
            public string _angel { get; set; }
            public string _tapesheet { get; set; }
            public string _topsheet { get; set; }
            public string _area { get; set; }
            public string _tag { get; set; }
            public string _ng { get; set; }
            public string _Exp { get; set; }
        }

        public class Cart_CNT_DS
        {
            public string _Count_date { get; set; }
            public Int32 _Cart_no { get; set; }
            public string _Area { get; set; }
            public string _Size { get; set; }
            public string _Forming { get; set; }
            public string _Meter { get; set; }
            public string _Ply { get; set; }
            public string _Top { get; set; }
            public string _Tape { get; set; }
            public string _Ng { get; set; }
            public string _Emp { get; set; }
            public string _Blank { get; set; }
            public string _Type { get; set; }
            public string _Exp { get; set; }
            public string _P1 { get; set; }
            public string _P2 { get; set; }
            public string _P3 { get; set; }
            public string _P4 { get; set; } 
            public string _cart_notuse { get; set; }
            public string _tag { get; set; }
            public string _export { get; set; }
            public string _user { get; set; }
        }

        public List<PlyRoll_DS> SEL_TAG(string biasno, string plandt
            , string itemno, string sitemno, string side, string rollno, bool std)
        {

            string ConnectionString = Nemo.GetConfiguredDbConnectionWrappertostring("Database");

            SqlConnection cnn = new SqlConnection(ConnectionString);
            StringBuilder str = new StringBuilder();
      
            str.AppendLine(" select  case when side='L' then Ply1 when side='R' then Ply2 else side end ply,a.* ");
            if (std) str.AppendLine(" ,isnull(TapeSheet,0) TapeSheet ,isnull(TopSheet,0) TopSheet ");
            str.AppendLine(" from " + Nemo.GetINI("Dbase", "Bias") + ".dbo.allRelation a ");
            if (std)
            {
                str.AppendLine("  inner join " + Nemo.GetINI("Dbase", "TIRSTD") + ".dbo.TIRSTD b ");
                str.AppendLine("on a.[sizes]=b.[sizes] and topcrdcd=tirecode and a.forming=b.forming ");
                str.AppendLine("inner join " + Nemo.GetINI("Dbase", "TIRSTD") + ".dbo.TIRSTD_DES c on b.tireid=c.tireid  ");
                str.AppendLine("and 'P'+ c.ply=(case when side='L' then a.Ply1 when side='R' then a.Ply2 else side end) ");
            }
            str.AppendLine("where biasno=@biasno and plandt = convert(datetime,@dtpln,120)");
            str.AppendLine("and itemno=@itemno and sitemno=@sitemno and side=@side and rollno=@rollno");

            if (std)
            {
                str.AppendLine(" and getdate() between b.validFrom and b.validTo ");
            }

            SqlCommand cmd = new SqlCommand(str.ToString() + "", cnn);
            cmd.Connection.Open();
            cmd.CommandType = CommandType.Text;

      
            cmd.Parameters.Add("@biasno", SqlDbType.VarChar).Value = biasno;
            cmd.Parameters.Add("@side", SqlDbType.VarChar).Value = side;
            cmd.Parameters.Add("@sitemno", SqlDbType.VarChar).Value = sitemno;
            cmd.Parameters.Add("@itemno", SqlDbType.VarChar).Value = itemno;
            cmd.Parameters.Add("@rollno", SqlDbType.VarChar).Value = rollno;
            cmd.Parameters.Add("@dtpln", SqlDbType.VarChar).Value = DateUtil.ToInternalDate(plandt, WinNemoLib.DateUtil.eLanguage.EN);


            SqlDataAdapter my = new SqlDataAdapter();
            DataSet ds = new DataSet();
            my.SelectCommand = cmd;
            my.Fill(ds);
            List<PlyRoll_DS> list = new List<PlyRoll_DS>();
            if (ds.Tables[0].Rows.Count <= 0)
            {
                cmd.Connection.Close();
                return list;
            }
            PlyRoll_DS model = new PlyRoll_DS();
            for (int cuIndex = 0; cuIndex < ds.Tables[0].Rows.Count; cuIndex++)
            {
                DataRow items = ds.Tables[0].Rows[cuIndex];
                model = new PlyRoll_DS();
                model._biasno = items["biasno"].ToString();
                model._plandt = DateUtil.ToDisplayDate(items["plandt"], DateUtil.eLanguage.EN);
                model._itemno = items["itemno"].ToString();
                model._sitemno = items["sitemno"].ToString();
                model._topcode = items["topcrdcd"].ToString();
                model._sizes = items["sizes"].ToString();
                model._forming = items["forming"].ToString();
                model._Ply = items["Ply"].ToString();
                model._cartno = items["cartno"].ToString();
                model._rollno = items["rollno"].ToString();
                model._side = items["side"].ToString();
                
                model._Exp = DateUtil.ToDisplayDate(items["plyexp"], DateUtil.eLanguage.EN);
                if (std)
                {
                    model._topsheet = items["TopSheet"].ToString();
                    model._tapesheet = items["TapeSheet"].ToString();
                }
                list.Add(model);
            }

            return list;
        }

        public Boolean Ins_Data_Blank(ConnectionWrapper cnn, PlyRoll_DS incoming, string usernm)
        {
            try
            {
                StringBuilder comstr = new StringBuilder();
                comstr.AppendLine(" INSERT INTO ");
                comstr.AppendLine(Nemo.GetINI("Dbase", "Base") + ".[dbo].[CountCart]");
                comstr.AppendLine("([Count_Date], [Cart_No], [Area] ");
                comstr.AppendLine(",[CartBlank], [ModifyBy] )");
                comstr.AppendLine(" values( getdate(),@cartno,@area");                
                comstr.AppendLine(" ,'X',@empname )");
                

                CommandWrapper cmd = cnn.CreateCommand();
                cmd.CommandText = comstr.ToString();



                cmd.AddParameterStringWithValue("@cartno", incoming._cartno);
                cmd.AddParameterStringWithValue("@area", incoming._area);  
                cmd.AddParameterStringWithValue("@empname", usernm);



                if (cmd.ExecuteNonQuery() <= 0)
                {
                    cnn.RollbackTransaction();
                    return false;
                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
                throw ex;
            }

        }

        public Boolean Ins_Data_Cart(ConnectionWrapper cnn, PlyRoll_DS incoming, string usernm)
        {
            try
            {
                StringBuilder comstr = new StringBuilder();
                comstr.AppendLine(" INSERT INTO ");
                comstr.AppendLine(Nemo.GetINI("Dbase", "Base") + ".[dbo].[CountCart]");
                comstr.AppendLine("([Count_Date], [Cart_No], [Area], [Sizes], [Forming], [PLY],  ");
                comstr.AppendLine(" [Meter], [mTop], [mTape], [Ng],Tag ");
                comstr.AppendLine(" ,[ModifyBy], [plandt], [itemno], [sitemno], [side], [rollno],biasno,Expiredate)");
                comstr.AppendLine(" values ( ");
                comstr.AppendLine(" getdate(),@cartno,@area, @sizes,@forming");
                comstr.AppendLine(",@ply,@meter,@top,@tape,@ng,@tag ");
                comstr.AppendLine(",@empname");
                comstr.AppendLine(",convert(datetime,@plandt,120),@itemno,@sitemno,@side,@rollno,@biasno,convert(datetime,@exp,120) )");

                CommandWrapper cmd = cnn.CreateCommand();
                cmd.CommandText = comstr.ToString();


                cmd.AddParameterStringWithValue("@biasno", incoming._biasno.Trim());
                cmd.AddParameterStringWithValue("@plandt", DateUtil.ToInternalDate(incoming._plandt, WinNemoLib.DateUtil.eLanguage.EN));
                cmd.AddParameterStringWithValue("@itemno", incoming._itemno);
                cmd.AddParameterStringWithValue("@sitemno", incoming._sitemno);
                cmd.AddParameterStringWithValue("@side", incoming._side);
                cmd.AddParameterStringWithValue("@rollno", incoming._rollno);
                cmd.AddParameterStringWithValue("@area", incoming._area);
                cmd.AddParameterStringWithValue("@empname", usernm);
                cmd.AddParameterStringWithValue("@cartno", incoming._cartno);
                cmd.AddParameterStringWithValue("@sizes", incoming._sizes);
                cmd.AddParameterStringWithValue("@forming", incoming._forming);
                cmd.AddParameterStringWithValue("@ply", incoming._Ply);
                cmd.AddParameterStringWithValue("@meter", incoming._plylen);
                cmd.AddParameterStringWithValue("@top", incoming._topsheet);
                cmd.AddParameterStringWithValue("@tape", incoming._tapesheet);
                cmd.AddParameterStringWithValue("@ng", incoming._ng);
                cmd.AddParameterStringWithValue("@tag", incoming._tag);
                cmd.AddParameterStringWithValue("@exp", DateUtil.ToInternalDate(incoming._Exp, WinNemoLib.DateUtil.eLanguage.EN));

                if (cmd.ExecuteNonQuery() <= 0)
                {
                    cnn.RollbackTransaction();
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
                throw ex;
            }

        }

        public Boolean Del_Data_Cart(ConnectionWrapper cnn,string cartno)
        {
            try
            {
                StringBuilder comstr = new StringBuilder();
                comstr.AppendLine(" Delete ");
                comstr.AppendLine(Nemo.GetINI("Dbase", "Base") + ".[dbo].[CountCart]");
                comstr.AppendLine(" where cart_no=@cartno and convert(datetime, convert(varchar, count_date,112),120)= convert(datetime, convert(varchar, getdate(),112),120)   ");


                CommandWrapper cmd = cnn.CreateCommand();
                cmd.CommandText = comstr.ToString();


                cmd.AddParameterStringWithValue("@cartno", cartno.Trim());
                cmd.ExecuteNonQuery();
   
                return true;
            }
            catch (Exception ex)
            {
                return false;
                throw ex;
            }

        }

        public Boolean Upd_Data_Exp(ConnectionWrapper cnn, string dCount, Boolean nonExp =false )
        {
            try
            {
                StringBuilder comstr = new StringBuilder();
                comstr.AppendLine(" UPDATE");
                comstr.AppendLine(Nemo.GetINI("Dbase", "Base") + ".[dbo].[CountCart]");
                comstr.AppendLine(" SET Export='X' ");
                comstr.AppendLine(" where  convert(datetime, convert(varchar, count_date,112),120) = convert(datetime,@dCount,120)  ");
                if (nonExp)
                {
                    comstr.AppendLine(" and export is null");
                }
                CommandWrapper cmd = cnn.CreateCommand();
                cmd.CommandText = comstr.ToString();
                cmd.AddParameterStringWithValue("@dCount", DateUtil.ToInternalDate(dCount, WinNemoLib.DateUtil.eLanguage.EN));
                if (cmd.ExecuteNonQuery() <= 0)
                {
                    cnn.RollbackTransaction();
                    return false;
                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
                throw ex;
            }

        }

        public List<Cart_CNT_DS> List_Count(string cartno = "",Boolean Todays=true
            ,string size="",string dCount="",string tag="")
        {
            string ConnectionString = Nemo.GetConfiguredDbConnectionWrappertostring("Database");
            string wh = " where ";
            SqlConnection cnn = new SqlConnection(ConnectionString);
            StringBuilder str = new StringBuilder();
            str.AppendLine(" SELECT a.[Count_Date], a.[Cart_No], a.[Area], a.[Sizes]");
            str.AppendLine(", a.[Forming], a.[PLY], a.[Meter], a.[mTop], a.[Ng], a.[mTape], a.[CartBlank],b.cart_type,b.Cart_notuse");            
            str.AppendLine(",case when a.ply='P1' then a.meter else null end P1");
            str.AppendLine(",case when a.ply='P2' then a.meter else null end P2");
            str.AppendLine(",case when a.ply='P3' then a.meter else null end P3");
            str.AppendLine(",case when a.ply='P4' then a.meter else null end P4");
            str.AppendLine(",a.modifyby,export,tag ,[expiredate] ");
            str.AppendLine(" from " + Nemo.GetINI("Dbase", "Base") + ".dbo.CountCart a");
            str.AppendLine(" Left join " + Nemo.GetINI("Dbase", "Base") + ".dbo.CartMaster b on a.cart_no=b.cart_no ");

            if (StrUtil.IsNotEmpty(size))
            {
                str.AppendLine(wh + " sizes = @size ");
                wh = " and ";
            }
            if (StrUtil.IsNotEmpty(cartno))
            {
                str.AppendLine(wh + "convert(varchar, a.cart_no)=@cartno ");
                wh = " and ";
            }
            if (StrUtil.IsNotEmpty(dCount))
            {
                str.AppendLine(wh + " convert(datetime, convert(varchar, a.count_date,112),120) = convert(datetime,@dCount,120) ");
                wh = " and ";
            }
            if (StrUtil.IsNotEmpty(tag))
            {
                str.AppendLine(wh + " tag=@tag ");
                wh = " and ";
            }
            if (Todays)
            {
                str.AppendLine(wh + " convert(datetime, convert(varchar, a.count_date,112),120)= convert(datetime, convert(varchar, getdate(),112),120) ");
            }
            SqlCommand cmd = new SqlCommand(str.ToString() + " order by convert(int,a.cart_no) ", cnn);
            cmd.Connection.Open();
            cmd.CommandType = CommandType.Text;

            if (StrUtil.IsNotEmpty(cartno)) cmd.Parameters.Add("@cartno", SqlDbType.VarChar).Value = cartno;
            if (StrUtil.IsNotEmpty(size)) cmd.Parameters.Add("@size", SqlDbType.VarChar).Value = size;
            if (StrUtil.IsNotEmpty(tag)) cmd.Parameters.Add("@tag", SqlDbType.VarChar).Value = tag;
            if (StrUtil.IsNotEmpty(dCount)) cmd.Parameters.Add("@dCount", SqlDbType.VarChar).Value = DateUtil.ToInternalDate(dCount, WinNemoLib.DateUtil.eLanguage.EN);

            SqlDataAdapter my = new SqlDataAdapter();
            DataSet ds = new DataSet();
            my.SelectCommand = cmd;
            my.Fill(ds);
            List<Cart_CNT_DS> list = new List<Cart_CNT_DS>();
            if (ds.Tables[0].Rows.Count <= 0)
            {
                cmd.Connection.Close();
                return list;
            }
          
            for (int cuIndex = 0; cuIndex < ds.Tables[0].Rows.Count; cuIndex++)
            {  
                Cart_CNT_DS model = new Cart_CNT_DS();
                DataRow items = ds.Tables[0].Rows[cuIndex];
                model._Count_date = DateUtil.ToDisplayDateTime(items["Count_Date"], DateUtil.eLanguage.EN);
                model._Cart_no = Convert.ToInt32(items["cart_no"]);
                model._Area = items["area"].ToString();
                model._Size = items["sizes"].ToString();
                model._Forming = items["forming"].ToString();
                model._Ply = items["ply"].ToString();
                model._Meter = items["meter"].ToString();
                model._Top = items["mTop"].ToString();
                model._Tape = items["mtape"].ToString();
                model._Blank = items["cartblank"].ToString();
                model._Type = items["cart_type"].ToString().ToUpper();
                model._cart_notuse = items["Cart_notuse"].ToString();
                model._Exp = DateUtil.ToDisplayDate(items["expiredate"], DateUtil.eLanguage.EN);
                model._tag = items["tag"].ToString();
                model._P1 = items["P1"].ToString();
                model._P2 = items["P2"].ToString();
                model._P3 = items["P3"].ToString();
                model._P4 = items["P4"].ToString();
                model._export = items["export"].ToString();
                model._Ng = items["ng"].ToString();
                model._user = items["modifyby"].ToString();
                list.Add(model);
            }
            return list;
        }


        public List<Cart_CNT_DS> List_Cart_Count(string dCount)
        {
            string ConnectionString = Nemo.GetConfiguredDbConnectionWrappertostring("Database");
            string wh = " where ";
            SqlConnection cnn = new SqlConnection(ConnectionString);
            StringBuilder str = new StringBuilder();

            str.AppendLine(" Select b.cart_no ,b.cart_type ,b.Cart_notuse ,P1,P2,P3,P4 ");
            str.AppendLine(" , a.[Count_Date], a.[Area], a.[Sizes]");
            str.AppendLine(", a.[Forming], a.[PLY], a.[Meter], a.[mTop], a.[Ng], a.[mTape], a.[CartBlank]");
            str.AppendLine(",a.modifyby,a.export,a.tag ,a.[expiredate] ");
            str.AppendLine(" from " + Nemo.GetINI("Dbase", "Base") + ".dbo.CartMaster b LEFT JOIN (");
            str.AppendLine(" SELECT a.[Count_Date], a.[Cart_No], a.[Area], a.[Sizes]");
            str.AppendLine(", a.[Forming], a.[PLY], a.[Meter], a.[mTop], a.[Ng], a.[mTape], a.[CartBlank]");
            str.AppendLine(",case when a.ply='P1' then a.meter else null end P1");
            str.AppendLine(",case when a.ply='P2' then a.meter else null end P2");
            str.AppendLine(",case when a.ply='P3' then a.meter else null end P3");
            str.AppendLine(",case when a.ply='P4' then a.meter else null end P4");
            str.AppendLine(",a.modifyby,export,tag ,[expiredate] ");
            str.AppendLine(" from " + Nemo.GetINI("Dbase", "Base") + ".dbo.CountCart a");           

            if (StrUtil.IsNotEmpty(dCount))
            {
                str.AppendLine(wh + " convert(datetime, convert(varchar, a.count_date,112),120) = convert(datetime,@dCount,120) ");
                wh = " and ";
            }
             str.AppendLine(" ) a  on a.cart_no=b.cart_no  ");
            SqlCommand cmd = new SqlCommand(str.ToString() + " order by convert(int,b.cart_no) ", cnn);
            cmd.Connection.Open();
            cmd.CommandType = CommandType.Text;


            if (StrUtil.IsNotEmpty(dCount)) cmd.Parameters.Add("@dCount", SqlDbType.VarChar).Value = DateUtil.ToInternalDate(dCount, WinNemoLib.DateUtil.eLanguage.EN);

            SqlDataAdapter my = new SqlDataAdapter();
            DataSet ds = new DataSet();
            my.SelectCommand = cmd;
            my.Fill(ds);
            List<Cart_CNT_DS> list = new List<Cart_CNT_DS>();
            if (ds.Tables[0].Rows.Count <= 0)
            {
                cmd.Connection.Close();
                return list;
            }

            for (int cuIndex = 0; cuIndex < ds.Tables[0].Rows.Count; cuIndex++)
            {
                Cart_CNT_DS model = new Cart_CNT_DS();
                DataRow items = ds.Tables[0].Rows[cuIndex];
                model._Count_date = DateUtil.ToDisplayDateTime(items["Count_Date"], DateUtil.eLanguage.EN);
                model._Cart_no =Convert.ToInt32(items["cart_no"]);
                model._Area = items["area"].ToString();
                model._Size = items["sizes"].ToString();
                model._Forming = items["forming"].ToString();
                model._Ply = items["ply"].ToString();
                model._Meter = items["meter"].ToString();
                model._Top = items["mTop"].ToString();
                model._Tape = items["mtape"].ToString();
                model._Blank = items["cartblank"].ToString();
                model._Type = items["cart_type"].ToString().ToUpper();
                model._cart_notuse = items["Cart_notuse"].ToString();
                model._Exp = DateUtil.ToDisplayDate(items["expiredate"], DateUtil.eLanguage.EN);
                model._tag = items["tag"].ToString();
                model._P1 = items["P1"].ToString();
                model._P2 = items["P2"].ToString();
                model._P3 = items["P3"].ToString();
                model._P4 = items["P4"].ToString();
                model._export = items["export"].ToString();
                model._Ng = items["ng"].ToString();
                model._user = items["modifyby"].ToString();
                list.Add(model);
            }
            return list;
        }

        public List<Cart_CNT_DS> List_Export(string dCount = "",bool nonExport = false,bool Export = false)
        {
            StringBuilder strWhere = new StringBuilder(" where cartblank is null");
            string wh = " and ";

            if (StrUtil.IsNotEmpty(dCount))
            {
                strWhere.AppendLine(wh + " convert(datetime, convert(varchar, a.count_date,112),120) = convert(datetime,@dCount,120) ");
                wh = " and ";
            }
            if (nonExport == true)
            {
                strWhere.AppendLine(wh + " export is null ");
            }
            else if (Export == true)
            {
                strWhere.AppendLine(wh + " export is not null ");

            }

            string ConnectionString = Nemo.GetConfiguredDbConnectionWrappertostring("Database");
   
            SqlConnection cnn = new SqlConnection(ConnectionString);
            StringBuilder str = new StringBuilder();

            str.AppendLine(" select Count_date,sizes,forming,mtop,ng,mtape,cart_type");
            str.AppendLine(" ,sum(P1) P1 ,sum(P2) P2");
            str.AppendLine(" ,sum(P3) P3,sum(P4) P4");
            str.AppendLine(" , [expiredate]");
            str.AppendLine(" from ( ");
            str.AppendLine("  SELECT convert(datetime, convert(varchar, a.count_date,112),120) [Count_Date], a.[Sizes] ");
            str.AppendLine(", a.[Forming], a.[mTop], a.[Ng], a.[mTape],b.cart_type");
            str.AppendLine(",case when a.ply='P1' then a.meter else null end P1");
            str.AppendLine(",case when a.ply='P2' then a.meter else null end P2");
            str.AppendLine(",case when a.ply='P3' then a.meter else null end P3");
            str.AppendLine(",case when a.ply='P4' then a.meter else null end P4");
            str.AppendLine(",case when [expiredate] < DATEADD ( day,3, convert(datetime, convert(varchar, getdate(),112),120) ) then [expiredate] else null end [expiredate] ");
            str.AppendLine(",DATEADD ( day,2, convert(datetime, convert(varchar, getdate(),112),120) ) D_Exp ");
            str.AppendLine(" from " + Nemo.GetINI("Dbase", "Base") + ".dbo.CountCart a");
            str.AppendLine(" Left join " + Nemo.GetINI("Dbase", "Base") + ".dbo.CartMaster b on a.cart_no=b.cart_no ");
            str.AppendLine(strWhere.ToString());


            SqlCommand cmd = new SqlCommand(str.ToString() + " ) a group by Count_date,sizes,forming,mtop,ng,mtape,cart_type,  [expiredate] ", cnn);
            cmd.Connection.Open();
            cmd.CommandType = CommandType.Text;

            if (StrUtil.IsNotEmpty(dCount)) cmd.Parameters.Add("@dCount", SqlDbType.VarChar).Value = DateUtil.ToInternalDate(dCount, WinNemoLib.DateUtil.eLanguage.EN);

            SqlDataAdapter my = new SqlDataAdapter();
            DataSet ds = new DataSet();
            my.SelectCommand = cmd;
            my.Fill(ds);
            List<Cart_CNT_DS> list = new List<Cart_CNT_DS>();
            if (ds.Tables[0].Rows.Count <= 0)
            {
                cmd.Connection.Close();
                return list;
            }

            for (int cuIndex = 0; cuIndex < ds.Tables[0].Rows.Count; cuIndex++)
            {
                Cart_CNT_DS model = new Cart_CNT_DS();
                DataRow items = ds.Tables[0].Rows[cuIndex];
                model._Count_date = DateUtil.ToDisplayDate(items["Count_Date"], DateUtil.eLanguage.EN);
                model._Size = items["sizes"].ToString();
                model._Forming = items["forming"].ToString();
                model._Top = items["mTop"].ToString();
                model._Tape = items["mtape"].ToString();
                model._Type = items["cart_type"].ToString().ToUpper();
                model._Exp = DateUtil.ToDisplayDate(items["expiredate"], DateUtil.eLanguage.EN);
                model._P1 = items["P1"].ToString();
                model._P2 = items["P2"].ToString();
                model._P3 = items["P3"].ToString();
                model._P4 = items["P4"].ToString();
                model._Ng = items["ng"].ToString();
                list.Add(model);
            }
            return list;
        }

    }
}